package yijy.threadExample;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yijy on 2017/7/28.
 */
public class ThreadLocal<T> {
    private Map<Runnable,T> values= Collections.synchronizedMap(new HashMap<Runnable, T>());

    public T get(){
        Thread t1= Thread.currentThread();
        T o = values.get(t1);
        if(o==null && !values.containsKey(t1)){
            o=initValue();
            values.put(t1,o);
        }
        return o;
    }

    public void set(T o){
        values.put(Thread.currentThread(),o);
    }

    public T initValue(){
        return null;
    }
}
